﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.Model;
using Hangjing.SQLServerDAL;
using Hangjing.Common;

namespace Html5
{
    public partial class registerdetail : System.Web.UI.Page
    {
        ECustomer userBLL = new ECustomer();
        protected void Page_Load(object sender, EventArgs e)
        {
            gocart.HRef = "login.aspx";

            string state = SectionProxyData.GetSetValue(39);
            if (state == "0")
            {
                this.div_gsmCode.Style["display"] = "none";
            }


            if (Request.HttpMethod.ToUpper() == "POST")//获取post信息，提交订单
            {
                add_Click();
            }
        }

        /// <summary>
        /// 提交注册订单
        /// </summary>
        protected void add_Click()
        {
            string tbphone = WebUtility.InputText(Request["tbmobile"]);
            string tbGsmCode = WebUtility.InputText(Request["tbGsmCode"]);//验证码
            string password = WebUtility.GetMd5(Request.Form["TBpassword"]);
            string website = WebUtility.InputText("beijing");

            this.tbmobile.Value = tbphone;

            #region 验证判断
             string state = SectionProxyData.GetSetValue(39);
             if (state == "1")//表示要验证    
             {
                 if (Session["RegisterGsmCode"] == null || Session["RegisterGsmCode"].ToString() != tbGsmCode.Trim())
                 {
                     divError.InnerHtml = "短信验证码错误！";
                     return;
                 }
             }

            string sql = "[Name] = '" + tbphone + "'";
            int count = userBLL.GetCount(sql);
            if (count > 0)
            {
                divError.InnerHtml = "该手机号已注册，请重新输入！";
                return;
            }

            sql = "Tell = '" + tbphone + "'";
            count = userBLL.GetCount(sql);
            if (count > 0)
            {
                divError.InnerHtml = "手机号码重复了，请重新输入！";
                return;
            }
            #endregion

            ECustomerInfo model = new ECustomerInfo();
            int point = Convert.ToInt32(SectionProxyData.GetSetValue(19));
            model.EMAIL = "";
            model.Name = tbphone;
            model.TrueName = "";
            model.Tell = tbphone;
            model.Password = password;
            model.RegTime = DateTime.Now;
            model.Point = point;
            model.IsActivate = -1;
            model.ActivateCode = WebUtility.RandStr(200);
            model.GroupID = 0;
            model.WebSite = website;
            model.RID = "0";
            model.Usermoney = 0;
            model.PhoneActivate = 0;
            model.Sex = "";
            model.MSN = "";

            if (userBLL.Add(model) > 0)
            {
                ECustomerInfo customer = userBLL.GetModelByNameAPassword(tbphone, model.Password);

                EPointRecordInfo info = new EPointRecordInfo();
                info.UserID = customer.DataID;
                info.Point = point;
                info.Event = "新注册用户,获得积分" + point + "个";
                info.Time = DateTime.Now;
                EPointRecord bll = new EPointRecord();
                bll.Add(info);

                string url = "~/Login.aspx?name=" + tbphone;

                Response.Redirect(url);
            }


        }
    }
}
